/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.vportal.portlet.vadvman.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.vportal.portlet.vadvman.model.AdvType;
import com.vportal.portlet.vadvman.model.AdvTypeModel;
import com.vportal.portlet.vadvman.model.AdvTypeSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the AdvType service. Represents a row in the &quot;AdvType&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.vportal.portlet.vadvman.model.AdvTypeModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AdvTypeImpl}.
 * </p>
 *
 * @author DucNN
 * @see AdvTypeImpl
 * @see com.vportal.portlet.vadvman.model.AdvType
 * @see com.vportal.portlet.vadvman.model.AdvTypeModel
 * @generated
 */
@JSON(strict = true)
public class AdvTypeModelImpl extends BaseModelImpl<AdvType>
	implements AdvTypeModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a adv type model instance should use the {@link com.vportal.portlet.vadvman.model.AdvType} interface instead.
	 */
	public static final String TABLE_NAME = "AdvType";
	public static final Object[][] TABLE_COLUMNS = {
			{ "typeId", Types.BIGINT },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "groupId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "name", Types.VARCHAR },
			{ "description", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table AdvType (typeId LONG not null primary key,createDate DATE null,modifiedDate DATE null,groupId LONG,companyId LONG,name VARCHAR(500) null,description VARCHAR(1000) null)";
	public static final String TABLE_SQL_DROP = "drop table AdvType";
	public static final String ORDER_BY_JPQL = " ORDER BY advType.createDate DESC";
	public static final String ORDER_BY_SQL = " ORDER BY AdvType.createDate DESC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.vportal.portlet.vadvman.model.AdvType"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.vportal.portlet.vadvman.model.AdvType"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.vportal.portlet.vadvman.model.AdvType"),
			true);
	public static long GROUPID_COLUMN_BITMASK = 1L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static AdvType toModel(AdvTypeSoap soapModel) {
		AdvType model = new AdvTypeImpl();

		model.setTypeId(soapModel.getTypeId());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setGroupId(soapModel.getGroupId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setName(soapModel.getName());
		model.setDescription(soapModel.getDescription());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<AdvType> toModels(AdvTypeSoap[] soapModels) {
		List<AdvType> models = new ArrayList<AdvType>(soapModels.length);

		for (AdvTypeSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.vportal.portlet.vadvman.model.AdvType"));

	public AdvTypeModelImpl() {
	}

	public long getPrimaryKey() {
		return _typeId;
	}

	public void setPrimaryKey(long primaryKey) {
		setTypeId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_typeId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return AdvType.class;
	}

	public String getModelClassName() {
		return AdvType.class.getName();
	}

	@JSON
	public long getTypeId() {
		return _typeId;
	}

	public void setTypeId(long typeId) {
		_typeId = typeId;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_columnBitmask = -1L;

		_createDate = createDate;
	}

	@JSON
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	public long getGroupId() {
		return _groupId;
	}

	public void setGroupId(long groupId) {
		_columnBitmask |= GROUPID_COLUMN_BITMASK;

		if (!_setOriginalGroupId) {
			_setOriginalGroupId = true;

			_originalGroupId = _groupId;
		}

		_groupId = groupId;
	}

	public long getOriginalGroupId() {
		return _originalGroupId;
	}

	@JSON
	public long getCompanyId() {
		return _companyId;
	}

	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	public String getName() {
		if (_name == null) {
			return StringPool.BLANK;
		}
		else {
			return _name;
		}
	}

	public void setName(String name) {
		_name = name;
	}

	@JSON
	public String getDescription() {
		if (_description == null) {
			return StringPool.BLANK;
		}
		else {
			return _description;
		}
	}

	public void setDescription(String description) {
		_description = description;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public AdvType toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (AdvType)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
					AdvType.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		AdvTypeImpl advTypeImpl = new AdvTypeImpl();

		advTypeImpl.setTypeId(getTypeId());
		advTypeImpl.setCreateDate(getCreateDate());
		advTypeImpl.setModifiedDate(getModifiedDate());
		advTypeImpl.setGroupId(getGroupId());
		advTypeImpl.setCompanyId(getCompanyId());
		advTypeImpl.setName(getName());
		advTypeImpl.setDescription(getDescription());

		advTypeImpl.resetOriginalValues();

		return advTypeImpl;
	}

	public int compareTo(AdvType advType) {
		int value = 0;

		value = DateUtil.compareTo(getCreateDate(), advType.getCreateDate());

		value = value * -1;

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		AdvType advType = null;

		try {
			advType = (AdvType)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = advType.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		AdvTypeModelImpl advTypeModelImpl = this;

		advTypeModelImpl._originalGroupId = advTypeModelImpl._groupId;

		advTypeModelImpl._setOriginalGroupId = false;

		advTypeModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<AdvType> toCacheModel() {
		AdvTypeCacheModel advTypeCacheModel = new AdvTypeCacheModel();

		advTypeCacheModel.typeId = getTypeId();

		Date createDate = getCreateDate();

		if (createDate != null) {
			advTypeCacheModel.createDate = createDate.getTime();
		}
		else {
			advTypeCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			advTypeCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			advTypeCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		advTypeCacheModel.groupId = getGroupId();

		advTypeCacheModel.companyId = getCompanyId();

		advTypeCacheModel.name = getName();

		String name = advTypeCacheModel.name;

		if ((name != null) && (name.length() == 0)) {
			advTypeCacheModel.name = null;
		}

		advTypeCacheModel.description = getDescription();

		String description = advTypeCacheModel.description;

		if ((description != null) && (description.length() == 0)) {
			advTypeCacheModel.description = null;
		}

		return advTypeCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(15);

		sb.append("{typeId=");
		sb.append(getTypeId());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", groupId=");
		sb.append(getGroupId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", name=");
		sb.append(getName());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(25);

		sb.append("<model><model-name>");
		sb.append("com.vportal.portlet.vadvman.model.AdvType");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>typeId</column-name><column-value><![CDATA[");
		sb.append(getTypeId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>groupId</column-name><column-value><![CDATA[");
		sb.append(getGroupId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = AdvType.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			AdvType.class
		};
	private long _typeId;
	private Date _createDate;
	private Date _modifiedDate;
	private long _groupId;
	private long _originalGroupId;
	private boolean _setOriginalGroupId;
	private long _companyId;
	private String _name;
	private String _description;
	private transient ExpandoBridge _expandoBridge;
	private long _columnBitmask;
	private AdvType _escapedModelProxy;
}